import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
/* Layout框架 */
import Layout from '@/layout'
export const constantRouterMap = [
  {
    name: 'login',
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
  })

export const asyncRouterMap = [

  {
    path: '/',
    component: Layout,
    redirect: '/userslist',
    name: 'Users',
    meta: { // 用户管理
      title: 'users',
      icon: 'user'
    },
    children: [
      {
        path: '/userslist',
        name: 'Userslist',
        component: () => import('@/views/basic/users/userslist'),
        meta: { title: 'userslist', noCache: false }, // 用户列表
        menu: 'userslist'
      },
      {
        path: '/newlyUser',
        name: 'NewlyUser',
        component: () => import('@/views/basic/users/newlyUser'),
        meta: { title: 'newlyUser', noCache: false }, // 新增用户
        hidden: true,
        menu: 'newlyUser'
      },
      {
        path: '/editUser/:id',
        name: 'EditUser',
        component: () => import('@/views/basic/users/editUser'),
        meta: { title: 'editUser', noCache: false }, // 修改用户
        hidden: true,
        menu: 'editUser'
      },
      {
        path: '/rulelist',
        name: 'Rulelist',
        component: () => import('@/views/basic/users/rulelist'),
        meta: { title: 'rulelist', noCache: false }, // 角色列表
        menu: 'rulelist'
      },
      {
        path: '/userGroup',
        name: 'UserGroup',
        component: () => import('@/views/basic/users/userGroup'),
        meta: { title: 'userGroup', noCache: false }, // 用户组列表
        menu: 'userGroup'
      },
      {
        path: '/menuList',
        name: 'MenuList',
        component: () => import('@/views/basic/users/menuList'),
        meta: { title: 'menuList' }, // 菜单管理
        menu: 'menuList'
      },
      {
        path: '/condition',
        name: 'Condition',
        component: () => import('@/views/basic/users/condition'),
        meta: { title: 'condition' }, // 查询条件列表
        menu: 'condition'
      },
      {
        path: '/dictionary',
        name: 'Dictionary',
        component: () => import('@/views/basic/dictionary'),
        meta: { title: 'dictionary' }, // 数据字典
        menu: 'dictionary'
      }
    ]
  },
  {
    path: '/resources',
    component: Layout,
    name: 'Resources',
    meta: { // 人力资源管理
      title: 'homanResources',
      icon: 'sale'
    },
    children: [
      {
        path: '/groupRoster',
        name: 'GroupRoster',
        component: () => import('@/views/resources/groupRoster'),
        meta: { title: 'groupRoster' }, // 集团花名册
        menu: 'groupRoster'
      },
      {
        path: '/humanAdd',
        name: 'humanAdd',
        component: () => import('@/views/resources/humanAdd'),
        meta: { title: 'humanAdd' }, // 新增人员
        hidden: true,
        menu: 'humanAdd'
      },
      {
        path: '/humanDetail/:id',
        name: 'humanDetail',
        component: () => import('@/views/resources/humanDetail'),
        meta: { title: 'humanDetail' }, // 人员详情
        hidden: true,
        menu: 'humanDetail'
      },
      {
        path: '/dayLaborer',
        name: 'DayLaborer',
        component: () => import('@/views/resources/dayLaborer'),
        meta: { title: 'dayLaborer' }, // 临时工管理
        menu: 'dayLaborer'
      }
    ]
  },
  {
    path: '/production',
    component: Layout,
    name: 'Production',
    meta: { // 生产管理
      title: 'production',
      icon: 'production'
    },
    children: [
      {
        path: '/collect ',
        component: () => import('@/views/production/collect/index'),
        name: 'Collect',
        meta: { title: 'collect' }, // 生产订单
        children: [
          {
            path: '/proOrderList',
            name: 'ProOrderList',
            component: () => import('@/views/production/collect/proOrderList'),
            meta: { title: 'proOrderList' }, // 生产订单列表
            menu: 'proOrderList'
          },
          {
            path: '/proOrderAdd',
            name: 'ProOrderAdd',
            component: () => import('@/views/production/collect/proOrderAdd'),
            meta: { title: 'proOrderAdd' }, // 生产订单新增
            menu: 'proOrderAdd'
          },
          {
            path: '/proOrderDetails/:id',
            name: 'ProOrderDetails',
            component: () =>
              import('@/views/production/collect/proOrderDetails'),
            meta: { title: 'proOrderDetails' }, // 生产订单详情
            hidden: true,
            menu: 'proOrderDetails'
          },
          {
            path: '/proGeneralOrd1/:id',
            name: 'ProGeneralOrd',
            component: () =>
              import('@/views/production/collect/proGeneralOrd1'),
            meta: { title: 'collect' }, // 生产订单
            hidden: true,
            menu: 'proGeneralOrd1'
          },
          {
            path: '/proSuccessionOrd1/:id',
            name: 'ProSuccessionOrd',
            component: () =>
              import('@/views/production/collect/proSuccessionOrd1'),
            meta: { title: 'collect' }, // 生产订单
            hidden: true,
            menu: 'proSuccessionOrd1'
          }
        ]
      },
      {
        path: '/process ',
        name: 'Process',
        redirect: '/workFlow',
        component: () => import('@/views/production/process/index'),
        meta: { title: 'process' }, // 工艺工序
        children: [
          {
            path: '/workFlow',
            name: 'WorkFlow',
            component: () => import('@/views/production/process/workFlow'),
            meta: { title: 'workFlow' }, // 生产流程单列表
            menu: 'workFlow'
          },
          {
            path: '/workFlowDetail/:id',
            name: 'WorKFlowDetail',
            component: () => import('@/views/production/process/workFlowDetail'),
            meta: { title: 'workFlowDetail' }, // 生产流程单详情
            hidden: true,
            menu: 'workFlowDetail'
          },
          {
            path: '/workFlowTong/:id',
            name: 'WorkFlowTong',
            component: () => import('@/views/production/process/workFlowTong'),
            meta: { title: 'workFlowOrder' }, // 生产流程单-套打
            hidden: true,
            menu: 'workFlowTong'
          },
          {
            path: '/workFlowTong2/:id',
            name: 'WorkFlowTong2',
            component: () => import('@/views/production/process/workFlowTong2'),
            meta: { title: 'workFlowOrder' }, // 生产流程单-套打
            hidden: true,
            menu: 'workFlowTong2'
          },
          {
            path: '/workFlowTong3/:id',
            name: 'workFlowTong3',
            component: () => import('@/views/production/process/workFlowTong3'),
            meta: { title: 'workFlowTong3' }, // 生产流程单-套打
            hidden: true,
            menu: 'workFlowTong'
          },
          {
            path: '/workOrder',
            name: 'WorkOrder',
            component: () =>
              import('@/views/production/process/workOrder'),
            meta: { title: 'workOrder' }, // 报工单列表
            menu: 'workOrder'
          },
          {
            path: '/workOrderDetail/:id',
            name: 'WorkOrderDetail',
            component: () =>
              import('@/views/production/process/workOrderDetail'),
            meta: { title: 'workOrderDetail' }, // 报工单详情
            hidden: true,
            menu: 'workOrderDetail'
          }
        ]
      }
    ]
  },
  {
    path: '/workshop',
    component: Layout,
    name: 'workshop',
    meta: { // 车间管理
      title: 'workshop',
      icon: 'workshop'
    },
    children: [
      {
        path: '/processLibrary',
        name: 'ProcessLibrary',
        redirect: '/processList',
        component: () => import('@/views/workshop'),
        meta: { title: 'processLibrary' }, // 工序库管理
        children: [
          {
            path: '/groupList',
            name: 'GroupList',
            component: () => import('@/views/workshop/groupList'),
            meta: { title: 'groupList' }, // 组别列表
            menu: 'groupList'
          },
          {
            path: '/processList',
            name: 'ProcessList',
            component: () =>
              import('@/views/workshop/processLibrary/processList'),
            meta: { title: 'processList' }, // 工序库列表
            menu: 'processList'
          },
          {
            path: '/processDetail',
            name: 'ProcessDetail',
            component: () =>
              import('@/views/workshop/processLibrary/processDetail'),
            meta: { title: 'processDetail' }, // 工序库详情
            hidden: true,
            menu: 'processDetail'
          },
          {
            path: '/technologyList',
            name: 'TechnologyList',
            component: () =>
              import('@/views/workshop/technology/technologyList'),
            meta: { title: 'technologyList' }, // 工艺模板列表
            menu: 'technologyList'
          },
          {
            path: '/technologyDetail/:id',
            name: 'TechnologyDetail',
            component: () =>
              import('@/views/workshop/technology/technologyDetail'),
            meta: { title: 'technologyDetail' }, // 工艺模板详情
            hidden: true,
            menu: 'technologyDetail'
          },
          {
            path: '/technologyAdd',
            name: 'TechnologyAdd',
            component: () =>
              import('@/views/workshop/technology/technologyAdd'),
            meta: { title: 'technologyAdd' }, // 新增工艺模板
            hidden: true,
            menu: 'technologyAdd'
          }
        ]
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
